﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using webapp4U.BOL;

namespace webapp4U.UI
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Load_Title();
         
            Pager.IndexChanged += new EventHandler(PageIndex_Changed);
            if (!Page.IsPostBack)
                this.DataBind();
        }

        private void PageIndex_Changed(Object sender, EventArgs e)
        {
            DataBind();
        }


        private void Load_Title()
        {
            Title.TitleName = ResourceManager.GetString("Product_SearchResult");
        }


        protected string GetPrice(decimal UnitPrice)
        {
            if (UnitPrice > 0)
                return Formatter.FormatMoney(UnitPrice).ToString() + " VNĐ";
            else
                return ResourceManager.GetString("Product_Price_Lienhe");
        }
       

        public override void DataBind()
        {
            string kq = Globals.GetStringFromQueryString("kq").Replace("Keyword", "");
            int ChatlieuID = Globals.GetIntFromQueryString("ChatlieuID");
            int PriceValue = Globals.GetIntFromQueryString("PriceValue");
            int CateID = Globals.GetIntFromQueryString("CateID");

            // hien thi bao nhieu hinh tren 1 trang
            Pager.PageSize = 12;

            List<Products> obj = Products.AdvanceSearch(kq, CateID, -1, ChatlieuID, PriceValue, Pager.PageIndex, Pager.PageSize);
            ItemsDataList.DataSource = obj;
            ItemsDataList.DataBind();

            Pager.TotalRecords = Products.GetCountAdvanceSearch(kq, CateID, -1, ChatlieuID, PriceValue);

            if (Pager.TotalRecords <= 0)
                PanelMsg.Visible = true;
            else
                PanelMsg.Visible = false;

            
            // kiem tra xem co can hien thi phan trang ko
            if (Pager.TotalRecords <= 1)
                DisplayPager.Visible = false;
            else
                DisplayPager.Visible = true;
        }

        protected string GetButtonAddToCart(Decimal UnitPrice)
        { 
            if(UnitPrice >0)
                if(Globals.LangVietNam())
                    return "<img src="+Globals.ImagesUrl()+"AddToCart_nho.gif border=0 />";
                else
                    return "<img src=" + Globals.ImagesUrl() + "AddToCart_nho_en.gif border=0 />";
            return "";
        }
    }
}